package com.sgb.kjwl.viewmodel.manage;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.api.EnterpriseAPIManager;
import com.sgb.kjwl.model.entity.enterprise.IpPickSelectEntity;
import com.sgb.kjwl.model.entity.manage.IPDetailEntity;
import com.swgk.core.base.model.entity.ListResponse;
import com.sgb.kjwl.view.ui.fragment.manage.IntellectualPropertyRightFragment;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 知识产权
 */
public class IntellectualPropertyRightModel extends BaseViewModel {

    private IntellectualPropertyRightFragment mFragment;
    IpPickSelectEntity entity1 = new IpPickSelectEntity("", "不限", "", "", "", "","");

    public IntellectualPropertyRightModel(IntellectualPropertyRightFragment intellectualPropertyRightFragment) {
        this.mFragment = intellectualPropertyRightFragment;
    }



    public void getCopyrightList(Map<String,Object> map) {
        DialogHelper.showProgressDialog(mFragment.getContext(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getManageAPI().getTrademarkListForShop(map).enqueue(new Callback<BaseEntity<ListResponse<List<IPDetailEntity>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<ListResponse<List<IPDetailEntity>>>> call, Response<BaseEntity<ListResponse<List<IPDetailEntity>>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    mFragment.showCopyrightList(response.body().getData().getList());
                } else {
                    MToast.showToast(mFragment.getContext(), response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<IPDetailEntity>>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });

    }

    /**
     * 获取商标类型
     */
    public void getTrademarkTypeOption() {
        DialogHelper.showProgressDialog(mFragment.getContext(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getManageAPI().getTrademarkTypeOptionForShop().enqueue(new Callback<BaseEntity<List<IpPickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<IpPickSelectEntity>>> call, Response<BaseEntity<List<IpPickSelectEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    ArrayList<IpPickSelectEntity> list1 = new ArrayList<>();
                    list1.addAll(response.body().getData());
                    list1.add(0, entity1);
                    mFragment.showPricePopWindow1(list1);
                } else {
                    MToast.showToast(mFragment.getActivity(), response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<IpPickSelectEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    /*
     * 获取版权分类选项
     */
    public void getCopyrightTypeOption() {
        DialogHelper.showProgressDialog(mFragment.getContext(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getManageAPI().getCopyRightTypeOptionForShop().enqueue(new Callback<BaseEntity<List<IpPickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<IpPickSelectEntity>>> call, Response<BaseEntity<List<IpPickSelectEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    MToast.showToast(mFragment.getActivity(), "暂无数据");
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    ArrayList<IpPickSelectEntity> list1 = new ArrayList<>();
                    list1.addAll(response.body().getData());
                    list1.add(0, entity1);
                    mFragment.showPricePopWindow1(list1);
                } else {
                    MToast.showToast(mFragment.getActivity(), response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<IpPickSelectEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }


    /*
     * 获取是否独家选项 本地写入数据
     */
    public void getIsOnlyOption() {
        IpPickSelectEntity entity1 = new IpPickSelectEntity("", "不限", "", "", "", "", "");
        IpPickSelectEntity entity2 = new IpPickSelectEntity("1", "独家", "", "", "", "", "");
        IpPickSelectEntity entity3 = new IpPickSelectEntity("2", "非独家", "", "", "", "", "");
        List<IpPickSelectEntity> onlyDatas = new ArrayList<>();
        onlyDatas.add(entity1);
        onlyDatas.add(entity2);
        onlyDatas.add(entity3);
        mFragment.showMakeupPopWindow(onlyDatas);

    }

    /**
     * 获取行业分类
     */
    public void queryIndustryCategry() {
        DialogHelper.showProgressDialog(mFragment.getContext(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().queryIndustryCategry().enqueue(new Callback<BaseEntity<List<IpPickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<IpPickSelectEntity>>> call, Response<BaseEntity<List<IpPickSelectEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    List<IpPickSelectEntity> list = new ArrayList<>();
                    list.addAll(response.body().getData());
                    list.add(0, entity1);
                    mFragment.showBrandPopWindow(list);
                } else {
                    MToast.showToast(mFragment.getActivity(), response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<IpPickSelectEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    /**
     * 专利类型
     */
    public void getPatentTypeOption() {
        DialogHelper.showProgressDialog(mFragment.getContext(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getManageAPI().getPatentTypeOptionForShop().enqueue(new Callback<BaseEntity<List<IpPickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<IpPickSelectEntity>>> call, Response<BaseEntity<List<IpPickSelectEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    List<IpPickSelectEntity> list = new ArrayList<>();
                    list.addAll(response.body().getData());
                    list.add(0, entity1);
                    mFragment.showPricePopWindow1(list);
                } else {
                    MToast.showToast(mFragment.getActivity(), response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<IpPickSelectEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }
}